package CommonPanel;

import java.awt.*;
import java.text.*;
import java.util.*;

import javax.swing.*;

import Clock.*;

public class HeaderPanel extends JPanel
{
	private GregorianCalendar calendar;
	private int hour, min, sec;
	private Clock clock;
	private ClockThread clockThread;
	private TitlePanel titlePanel;
	private GridBagConstraints gbc;
	
	public HeaderPanel()
	{
		setPreferredSize(new Dimension(200, 250));
		setLayout(new GridBagLayout());
		setBackground(Color.DARK_GRAY);
		
		createComponents();
		
		gbc = new GridBagConstraints();
		gbc.fill = GridBagConstraints.BOTH;
		
		gbc.insets = new Insets(0, 0, 0, 0);
		setPosition(0, 0);
		add(titlePanel, gbc);
		
		gbc.insets = new Insets(0, 0, 0, 0);
		setPosition(1, 0);
		add(clock, gbc);
	}
	
	private void setPosition (int x, int y) //Setting of gbc
	{
		gbc.gridx = x;
		gbc.gridy = y;
		gbc.gridwidth = 1;
		gbc.gridheight = 1;
	}
	
	public void createComponents()
	{
		calendar = new GregorianCalendar();
	    Calendar.getInstance(Locale.FRENCH); //Use the local time
	    
	    hour = calendar.get(GregorianCalendar.HOUR_OF_DAY);
	    min = calendar.get(GregorianCalendar.MINUTE);
	    sec = calendar.get(GregorianCalendar.SECOND);
	    
	    clock = new Clock(hour, min, sec, DateFormat.getDateInstance(DateFormat.LONG, Locale.getDefault())); //Creation of the clock and initialization
		clock.setPreferredSize(new Dimension(200, 100));
	    clockThread = new ClockThread(clock); 	
	    clockThread.start(); //Start the thread
	    
	    titlePanel = new TitlePanel();
	}
}